import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useTable } from "@/components/Table";
import "./index.less";
import { useTranslation } from "react-i18next";
import { PurPlanWhsApi } from "@/api/erp/purchase/purPlanWhs";
import { productApi } from "@/api/erp/drug/drug";
import { WarehouseApi } from "@/api/erp/stock/warehouse";
import { SupplierApi } from "@/api/erp/purchase/supplier";
const newAdd = (props: any) => {
	const en_vi = "drugStorage.purchasingManagement.other";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t("drugStorage.productName"),
			component: "ApiSelect",
			field: "drugId",
			componentProps: {
				api: productApi.getproductSimpleList,
				labelField: "productName",
				valueField: "productId",
				immediate: false,
				params: {
					bizType: "1"
				}
			}
		},
		{
			label: t("drugStorage.inventoryManagement.drugInventory.warehouseName"),
			field: "whsId",
			component: "ApiSelect",
			componentProps: {
				api: WarehouseApi.getWarehouseSimpleList1,
				labelField: "whsName",
				valueField: "whsId"
			}
		},
		{
			label: t(`${en_vi}.supler`),
			component: "ApiSelect",
			field: "suplerId",
			componentProps: {
				api: SupplierApi.getSupplierSimpleList,
				labelField: "name",
				valueField: "suplerId",
				immediate: false
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.whsId`),
			dataIndex: "whsId"
		},
		{
			title: t(`${en_vi}.planDate`),
			dataIndex: "planDate"
		},
		{
			title: t(`${en_vi}.drugId`),
			dataIndex: "drugId"
		},
		{
			title: t(`${en_vi}.qtyIn`),
			dataIndex: "qtyIn"
		},
		{
			title: t(`${en_vi}.qtyOut`),
			dataIndex: "qtyOut"
		},
		{
			title: t(`${en_vi}.stockQty`),
			dataIndex: "stockQty"
		},
		{
			title: t(`${en_vi}.counterQty`),
			dataIndex: "counterQty"
		},
		{
			title: t(`${en_vi}.total`),
			dataIndex: "total"
		},
		{
			title: t(`${en_vi}.level1`),
			dataIndex: "level1"
		},
		{
			title: t(`${en_vi}.level2`),
			dataIndex: "level2"
		},
		{
			title: t(`${en_vi}.level3`),
			dataIndex: "level3"
		},
		{
			title: t(`${en_vi}.level4`),
			dataIndex: "level4"
		},
		{
			title: t(`${en_vi}.supler`),
			dataIndex: "suplerId"
		},
		{
			title: t(`${en_vi}.unit`),
			dataIndex: "unit"
		},
		{
			title: t(`${en_vi}.unitPrice`),
			dataIndex: "unitPrice"
		},
		{
			title: t(`${en_vi}.price`),
			dataIndex: "price"
		},
		{
			title: t(`${en_vi}.fundingId`),
			dataIndex: "fundingId"
		},
		{
			title: t(`${en_vi}.number`),
			dataIndex: "number"
		},
		{
			title: t(`${en_vi}.execMeth`),
			dataIndex: "execMeth"
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: PurPlanWhsApi.getPurPlanWhsPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 8 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		useSearchForm: true
	});
	const handleSubmit = async () => {
		const orderItem = getSelectRows();
		props.setBizId(orderItem[0]?.id);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
